<template>
    <div class="pipe_btn">
        <div class="pipe-item" v-for="item in props.btn_data" :key="item.label">
            <div @click="click(item.label)" :class="active == item.label ? 'active' : 'btn'" class="btn">
                <div class="icon">
                    <img :src="item.icon" alt="" />
                </div>
                <div class="text">{{ item.label }}</div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { PropType, ref } from 'vue'
import { getAssetsFile } from '@/utils'
const props = defineProps({
    btn_data: {
        type: Array as PropType<{ label: string; icon: string }[]>,
        required: true,
        default: () => [
            {
                label: '按钮1',
                icon: getAssetsFile('home/icon_面积@2x.png')
            },
            {
                label: '按钮2',
                icon: getAssetsFile('home/icon_面积@2x.png')
            },
            {
                label: '按钮3',
                icon: getAssetsFile('home/icon_面积@2x.png')
            }
        ]
    }
})
let active = ref<string>('')

const emit = defineEmits(['change'])
const click = (key: string) => {
    const flag = !(active.value == key)
    const reKey = active.value
    if (flag) {
        active.value = key
    } else {
        active.value = ''
    }

    emit('change', {
        flag: flag,
        key: key,
        lastKey: reKey
    })
}

defineExpose({
    click
})
</script>

<style lang="scss" scoped>
.pipe_btn {
    z-index: 99;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: all 0.2s;
    padding: 30px 0 20px 0;
    .pipe-item {
        text-align: right;
    }
    .btn {
        width: 300px;
        height: 150px;
        box-sizing: border-box;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        background: url(img/subMenu_bg_current@2x.png) no-repeat;
        background-size: 100% 100%;
        margin-bottom: -30px;
        transition: all 0.2s;
        padding: 30px 0 50px 50px;
        .icon {
            width: 80px;
            height: 60px;
            padding-left: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            img {
                width: 40px;
                height: 40px;
            }
        }
        .text {
            width: 175px;
            font-size: 28px;
            display: flex;
            align-items: flex-start;
            justify-content: center;
            font-family: Tencent, serif;
            color: #89cbffcc;
            text-shadow: 0 3.27px 6.55px #00000080;
        }
        &:hover {
            transform: scale(1.03) translateX(0.1vw);
        }
    }

    .active {
        transform: scale(1.03) translateX(0.1vw);
        .text {
            font-weight: bold;
            color: #ffffff;
        }
    }
}
</style>
